package fragmentson;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.wq.cycling.R;

import activity.SonActivity;
import fragmentson.backhandle.BackHandledFragment;

/**
 * 支付
 * author：wangqi on 2017/4/26 17:48
 * email：773630555@qq.com
 */
public class Pay extends BackHandledFragment {

	private View rootView;
	private ImageView iv_alpay,iv_wxpay;
	/**
	 * 1支付宝 2微信
	 */
	private String paytype="1";
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		rootView = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_pay, null);
		initView();
		return rootView;
	}

	private void initView() {
		// TODO Auto-generated method stub
		((TextView) rootView.findViewById(R.id.tv_title)).setText(R.string.device_functions_recharge);
		rootView.findViewById(R.id.ll_alpay).setOnClickListener(listener);
		rootView.findViewById(R.id.ll_wxpay).setOnClickListener(listener);
		iv_alpay = ((ImageView) rootView.findViewById(R.id.iv_alpay));
		iv_wxpay = ((ImageView) rootView.findViewById(R.id.iv_wxpay));
		rootView.findViewById(R.id.tv_submit).setOnClickListener(listener);
	}


	public static Pay newInstance() {
		Pay fragment = new Pay();
		return fragment;
	}

	private View.OnClickListener listener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			switch (v.getId()){
				case R.id.ll_alpay:
					iv_alpay.setImageResource(R.mipmap.icon_device_select);
					iv_wxpay.setImageResource(R.mipmap.icon_device_unselect);
					paytype = "1";
					break;
				case R.id.ll_wxpay:
					iv_wxpay.setImageResource(R.mipmap.icon_device_select);
					iv_alpay.setImageResource(R.mipmap.icon_device_unselect);
					paytype = "2";
					break;
				case R.id.tv_submit:
					if(paytype.equals("1")){
						Toast.makeText(getActivity(),"支付宝",Toast.LENGTH_LONG).show();
					}else{
						Toast.makeText(getActivity(),"微信",Toast.LENGTH_LONG).show();
					}
					((SonActivity) getActivity()).backTask();
					((SonActivity) getActivity()).backTask();
					break;
				default:
					break;
			}
		}
	};


	@Override
	public boolean onBackPressed() {
		return false;
	}
	
}
